import { Card } from 'antd';
import React from 'react';
import emitter from '../utils/events';
const { Meta } = Card;

class DurgCard extends React.Component{
    
    constructor(props) {
        super(props);
        this.state= {
           title:this.props.title,
           src:this.props.src,
           content:this.props.content,
        }
    }

    componentDidMount() {
        // 组件装载完成以后声明一个自定义事件
        this.eventEmitter = emitter.addListener('changeDrug', (message) => {
            this.setState({
                title:message.title,
                src:message.src,
                content:message.indications
            });
        });
    }
    componentWillUnmount() {
        emitter.removeListener(this.eventEmitter);
    }

    render() {return(<Card
        hoverable
        style={{
            height:"70%",
            paddingLeft:"5%",
            width: "100%",
            paddingRight:"5%",
            paddingTop:"5%",
            overflowY:'scroll'
        }}
        cover={<img alt="" src={this.state.src} />}
      >
        <Meta style={{}} title={this.state.title} description={this.state.content} />
      </Card>)}
};

export default DurgCard;